package com.taijihuabao.common.commonutils;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageSerializable;

import java.util.List;

/**
 * @title: PageResult
 * @Author luoxianan
 * @Date: 2021/12/30 15:26
 * @Version 1.0
 */
public class PageResult<T> extends PageSerializable<T> {
    /**
     * 总记录数
     */
    private long  total;
    /**
     * 结果集
     */
    protected List<T> list;

    public PageResult() {
    }

    public PageResult(List<T> list) {
        this.list = list;
        if(list instanceof Page){
            this.total = ((Page)list).getTotal();
        } else {
            this.total = list.size();
        }
    }

    public static <T> PageSerializable<T> of(List<T> list){
        return new PageSerializable<T>(list);
    }

    @Override
    public long getTotal() {
        return total;
    }

    @Override
    public void setTotal(long total) {
        this.total = total;
    }

    @Override
    public List<T> getList() {
        return list;
    }

    @Override
    public void setList(List<T> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return "PageSerializable{" +
                "total=" + total +
                ", list=" + list +
                '}';
    }
}
